package com.wl156.adapters;

import org.ksoap2.serialization.SoapObject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wl156.R;

public class XinyongxingjiAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	SoapObject so;

	public XinyongxingjiAdapter(Context context, SoapObject so) {
		mInflater = LayoutInflater.from(context);
		this.so = so;
	}

	@Override
	public int getCount() {
		return so.getPropertyCount();
	}

	@Override
	public SoapObject getItem(int index) {
		return (SoapObject) so.getProperty(index);
	}

	@Override
	public long getItemId(int index) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = mInflater.inflate(R.layout.item_xinyongxingji, null);
		TextView startDate = (TextView) view.findViewById(R.id.startDate);
		TextView endDate = (TextView) view.findViewById(R.id.endDate);
		TextView startLocation = (TextView) view
				.findViewById(R.id.startLocation);
		TextView endLocation = (TextView) view.findViewById(R.id.endLocation);
		TextView score = (TextView) view.findViewById(R.id.score);
		
		setTextViewStringFromProperty(position, startDate, 0);
		setTextViewStringFromProperty(position, endDate, 1);
		setTextViewStringFromProperty(position, startLocation, 2);
		setTextViewStringFromProperty(position, endLocation, 3);
		setTextViewStringFromProperty(position, score, 4);

		return view;
	}

	protected void setTextViewStringFromProperty(int position, TextView tv,
			int index) {
		try {
			Object prop = getItem(position).getProperty(index);
			String text = "";
			if (prop != null) {
				text = prop.toString();
			}
			if (text.equals("anyType{}")) {
				text = "";
			}
			tv.setText(text);
		} catch (Exception e) {
		}
	}
}
